EWS send mail error "The request failed. operation timeout"

If I add an attachment to more than 1.2M, the prompt operation is timed out; however, the use of outlook to send mail is not limited to the size of the attachment

thanks!

c# coding:

	static void Main(string[] args)
        {
            try
            {
                string username = args[0];
                string password = args[1];
                string domain = args[2];
                string frommail = args[3];
                string subject = args[4];
                string body = args[5];
                string[] tos = args[6].Split(';');
                string[] files = args[7].Split(';');
		
                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
                
                service.Credentials = new WebCredentials(username, password, domain);
                service.TraceEnabled = true;
                service.TraceFlags = TraceFlags.All;
                service.AutodiscoverUrl(frommail, RedirectionUrlValidationCallback);
                EmailMessage email = new EmailMessage(service);
                
                foreach (string t in tos)
                {
                    email.ToRecipients.Add(t);
                }
                email.Subject = subject;
                email.Body = new MessageBody(body);
                foreach (string s in files)
                {
                    email.Attachments.AddFileAttachment(s);
                }
                
                email.Send();
            }
            catch (Exception ex)
            {
                System.IO.File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + "\\Error.log", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ")+ex.Message+"\r\n");
            }
        }
	private static bool RedirectionUrlValidationCallback(string redirectionUrl)
        {
            bool result = false;
            Uri redirectionUri = new Uri(redirectionUrl);
            if (redirectionUri.Scheme == "https")
            {
                result = true;
            }
            return result;
        }

July 12th, 2015 7:42pm

The default timeout is 90 seconds so if your upload doesn't complete in this time (due to very poor network connectivity) then you would get a timeout error. I would suggest you increase the timeout may 5 minutes to start with

service.timeout = 300000;

Cheers
Glen

Free Windows Admin Tool Kit Click here and download it now
July 12th, 2015 8:50pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics